package cn.kgc.student.controller;

import cn.kgc.student.pojo.Classes;
import cn.kgc.student.service.ClassesService;
import cn.kgc.student.utils.Page;
import cn.kgc.student.vo.ClassesParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：班级 控制器
* @author 魏耀
* @date 2019/07/22
*/
@RestController
@RequestMapping("/classes")
public class ClassesController{
	@Reference(version = "1.1")
    private ClassesService classesService;

    @Reference
    private ClassesService classesService2;
 	
 	@RequestMapping("/findById.json")
    public Classes findById(Integer id){
        Classes result = null;
        try {
            result = classesService.findById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Classes对象
     */
    @RequestMapping("/findAll.json")
    public List<Classes> findAll(){
        List<Classes> result = null;
        try {
            result = classesService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
    @RequestMapping("/findAll2.json")
    public List<Classes> findAll2(){
        List<Classes> result = null;
        try {
            result = classesService2.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Classes对象
     */
    @RequestMapping("/save.json")
    public Map save(Classes classes){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存班级失败");
        try {
            if(classesService.save(classes)>0){
                result.put("flag",true);
                result.put("msg","保存班级成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除班级对象
     * @param id
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer id){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存班级失败");
        try {
            if(classesService.delete(id)>0){
                result.put("flag",true);
                result.put("msg","保存班级成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新班级对象
     */
    @RequestMapping("/update.json")
    public Map update(Classes classes){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新班级失败");
        try {
            if( classesService.update(classes)>0){
                result.put("flag",true);
                result.put("msg","更新班级成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Classes> query(ClassesParam param){
        List<Classes> result = null;
        try {
            result = classesService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(ClassesParam param){
        Page result = null;
        try {
            result = classesService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
 }
